<?php
declare(strict_types=1);

namespace SixShop\WechatPay\Trait;

use SixShop\WechatPay\Facade\WechatPayBuilder;
use WeChatPay\Crypto\Rsa;
use WeChatPay\Formatter;

trait PaymentParamsTrait
{
    private function paymentParams(string $prepayID): array
    {
        $config = WechatPayBuilder::getConfig();
        $params = [
            'appId' => $config->appid,
            'timeStamp' => (string)Formatter::timestamp(),
            'nonceStr' => Formatter::nonce(),
            'package' => 'prepay_id=' . $prepayID,
        ];
        $params += ['paySign' => Rsa::sign(
            Formatter::joinedByLineFeed(...array_values($params)),
            $config->apiclient_key
        ), 'signType' => 'RSA'];
        return $params;
    }
}